using System;
using System.Collections.Generic;
using System.Text;

namespace Index.TemporaryFile
{
    public class TermEntry: IComparable<TermEntry>
    {
        private int term_id;
        private int document_id;
        private int position;

        public TermEntry(int term_id, int document_id, int position)
        {
            this.term_id = term_id;
            this.document_id = document_id;
            this.position = position;
        }

        public int TermID
        {
            get
            {
                return term_id;
            }

        }
        public int DocumentID
        {
            get
            {
                return document_id;
            }
        }

        public int Position
        {
            get
            {
                return position;
            }
        }

        public override bool Equals(object obj)
        {

            if (obj.GetType() == typeof(TermEntry))
            {
                TermEntry entry = (TermEntry)obj;

                return
                   (entry.DocumentID == this.DocumentID)
                && (entry.Position == this.Position)
                && (entry.TermID == this.TermID);
            }
            else
            {
                return false;
            }
        }


      
        public int CompareTo(TermEntry other)
        {
            int val = other.term_id - this.term_id;
            if (val == 0)
            {

                val = other.document_id - this.document_id;

                if (val == 0)
                {
                    val = other.position - this.position;

                    if (val == 0)
                    {
                        return 0;
                    }
                    else
                    {
                        if (val > 0)
                        {
                            return -1;
                        }
                        else
                        {
                            return 1;
                        }
                    }

                }
                else
                {
                    if (val > 0)
                    {
                        return -1;
                    }
                    else
                    {
                        return 1;
                    }
                }

                
            }
            else
            {
                if (val > 0)
                {
                    return -1;
                }
                else
                {
                    return 1;
                }
            }
        }

    }
}
